/* Copyright 2008. All rights reserved. */
package org.bling.parser.tags;

import org.bling.parser.BlingParserException;
import org.bling.swt.BlingLayoutData;
import org.bling.swt.widgets.Break;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Widget;

/**
 * Inserts a customer Break SWT widget on the composite, to
 * inform the layout renderer that widgets should now be
 * rendered on the next line (similar to an HTML <br /> tag)
 *  
 * @author DISBROB
 * 
 */
public class BreakTag extends Tag {

	protected Break br;

	@Override
	public int doStartTag() throws BlingParserException {
		super.doStartTag();

		if (!(parent.getWidget() instanceof Composite)) {
			throw new BlingParserException(
					"Label tags can only be inside of composites");
		}

		Composite composite = (Composite) parent.getWidget();
		br = new Break(composite);
		BlingLayoutData data = new BlingLayoutData();
		data.setLineBreak(true);
		data.width = 0;
		data.height = 0;
		br.setLayoutData(data);

		return EVAL_PAGE;
	}

	@Override
	public Widget getWidget() throws BlingParserException {
		return br;
	}

}
